home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / PowerPC / Dev / PPCRelease / Examples / IPC / Msg6PPC.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-06  |  4.1 KB  |  170 lines

  1. /* Msg6 and Msg6PPC.elf
  2.  *
  3.  * This test program sends 1000 messages to the M68k and
  4.  * shows how long this takes.
  5.  * The Messages are send asynchron and every msg must
  6.  * be replied after another.
  7.  * Each Message has the Body "Text sent by PPC processor\n"
  8.  */
  9.  
  10. #include <exec/types.h>
  11. #include <exec/nodes.h>
  12. #include <exec/lists.h>
  13. #include <exec/memory.h>
  14. #include <utility/tagitem.h>
  15. #include <powerup/ppclib/interface.h>
  16. #include <powerup/ppclib/message.h>
  17. #include <powerup/ppclib/tasks.h>
  18. #include <powerup/gcclib/powerup_protos.h>
  19.  
  20. #define    DEBUG    0
  21.  
  22. #if DEBUG
  23. #define    D(x)    x;
  24. #else
  25. #define    D(x)    ;
  26. #endif
  27.  
  28. #define TEXT    "Text sent by PPC processor\n"
  29.  
  30. BPTR        MyFile;
  31.  
  32. struct StartupData
  33. {
  34.     void    *MsgPort;
  35.     ULONG    MsgCount;
  36. };
  37.  
  38.  
  39. int    main(void)
  40. {
  41. struct TagItem        MyTags[10];
  42. struct StartupData    *StartupData;
  43. void            *ReplyPort;
  44. void            *M68kPort;
  45. void            *PPCMsg;
  46. void            *Body;
  47. ULONG            result;
  48. ULONG            MsgCount;
  49. ULONG            i;
  50. void            **MsgArray;
  51.  
  52.   StartupData    =(struct StartupData *) PPCGetTaskAttr(PPCTASKTAG_STARTUP_MSGDATA);
  53.   MsgCount    =    StartupData->MsgCount;
  54.  
  55. #if DEBUG
  56.   if (MyFile = PPCOpen("con:0/0/640/200/MessageDemo - PPC output/CLOSE", MODE_NEWFILE))
  57.   {
  58. #endif
  59.     if (MsgArray=(void**) PPCAllocVec(sizeof(void*) * MsgCount, MEMF_PUBLIC))
  60.     {
  61.       if (M68kPort=StartupData->MsgPort)
  62.       {
  63.         D(PPCfprintf(MyFile,"Allocating memory for message body\n"));
  64.         if (Body = PPCAllocVec(sizeof(TEXT), MEMF_PUBLIC))
  65.         {
  66.           D(PPCfprintf(MyFile,"Creating reply port\n"));
  67.           MyTags[0].ti_Tag = TAG_DONE;
  68.           if (ReplyPort = PPCCreatePort(MyTags))
  69.           {
  70.             D(PPCfprintf(MyFile,"Create 1000 Messages..."));
  71.  
  72.             for (i=0;i<MsgCount;i++)
  73.             {
  74.               if ((MsgArray[i]=PPCCreateMessage(ReplyPort,
  75.                                                 sizeof(TEXT)))==NULL)
  76.               {
  77.                 break;
  78.               }
  79.             }
  80.  
  81.             D(PPCfprintf(MyFile,"done\n"));
  82.  
  83.             if (i>=MsgCount)
  84.             {
  85.               D(PPCfprintf(MyFile,"Sending 1000 Messages..."));
  86.               strcpy(Body, TEXT);
  87.  
  88.               for (i=0;i<MsgCount;i++)
  89.               {
  90.                 PPCSendMessage(M68kPort,
  91.                                MsgArray[i],
  92.                                Body,
  93.                                sizeof(TEXT),
  94.                                i);
  95.               }
  96.  
  97.               D(PPCfprintf(MyFile,"done\n"));
  98.  
  99.               D(PPCfprintf(MyFile,"Waiting for 1000 Replies..."));
  100.  
  101.               i    =    0;
  102.  
  103.               while (i<MsgCount)
  104.               {
  105.                 PPCWaitPort(ReplyPort);
  106.                 while (i<MsgCount && (PPCMsg=PPCGetMessage(ReplyPort)))
  107.                 {
  108.                   D(PPCfprintf(MyFile,
  109.                                "MsgObject 0x%lx MsgID %ld ReceivedMsg %ld\n",
  110.                                PPCMsg,
  111.                                PPCGetMessageAttr(PPCMsg, PPCMSGTAG_MSGID),
  112.                                i));
  113.  
  114.                   i++;
  115.                 }
  116.               }
  117.  
  118.               D(PPCfprintf(MyFile,"done\n"));
  119.  
  120.               D(PPCfprintf(MyFile,"Deleting messages...\n"));
  121.  
  122.               for (i=0;i<MsgCount;i++)
  123.               {
  124.                 if (MsgArray[i])
  125.                 {
  126.                   PPCDeleteMessage(MsgArray[i]);
  127.                 }
  128.               }
  129.             }
  130.             else
  131.             {
  132.               D(PPCfprintf(MyFile,"Could not create ppc msg\n"));
  133.             }
  134.  
  135.             D(PPCfprintf(MyFile,"Deleting reply port\n"));
  136.  
  137.             while (PPCDeletePort(ReplyPort) == FALSE);
  138.           }
  139.           else
  140.           {
  141.             D(PPCfprintf(MyFile,"Could not create reply port\n"));
  142.           }
  143.  
  144.           D(PPCfprintf(MyFile,"Freeing message body memory\n"));
  145.           PPCFreeVec(Body);
  146.         }
  147.         else
  148.         {
  149.           D(PPCfprintf(MyFile,"Could not alloc mem for msg body\n"));
  150.         }
  151.       }
  152.       else
  153.       {
  154.         D(PPCfprintf(MyFile,"Could not get a M68k msgport\n"));
  155.       }
  156.       PPCFreeVec(MsgArray);
  157.     }
  158.     else
  159.     {
  160.       D(PPCfprintf(MyFile,"Could not alloc mem for msg array\n"));
  161.     }
  162.  
  163.     D(PPCfprintf(MyFile,"Closing output\n"));
  164. #if DEBUG
  165.     PPCClose(MyFile);
  166.   }
  167. #endif
  168. }
  169.  
  170.